/*
 * @Author: FengKongLi 
 * @Date: 2021-08-22 18:17:50 
 * @Last Modified by: FengKongLi
 * @Last Modified time: 2021-08-26 11:23:35
 */
//  员工账单管理页面
<template>
  <div>
    <!-- 查询 -->
    <div>
      <el-form :inline="true" :model="searchForm" class="demo-form-inline">
        <el-form-item>
          <el-date-picker
            value-format="timestamp"
            v-model="dataValue"
            type="datetimerange"
            :picker-options="pickerOptions"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-select
            clearable
            v-model="searchForm.type"
            placeholder="请选择交易类型"
          >
            <el-option label="收益" value="收益"></el-option>
            <el-option label="提现" value="提现"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            clearable
            v-model="searchForm.status"
            placeholder="请选择状态"
          >
            <el-option label="正常" value="正常"></el-option>
            <el-option label="未审核" value="未审核"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            clearable
            v-model="searchForm.userId"
            placeholder="员工编号"
          >
            <el-option
              v-for="item in employeeData"
              :key="item.id"
              :label="item.username"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="toSearch">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- {{ tableData }} -->
    <!-- 表格数据展示 -->
    <div>
      <el-table :data="tableData" stripe style="width: 100%">
        <el-table-column prop="id" label="编号"> </el-table-column>
        <el-table-column prop="transferMoney" label="交易金额">
        </el-table-column>
        <el-table-column
          prop="transferTime"
          label="交易时间"
          :formatter="fmtTableDateDay"
        >
        </el-table-column>
        
        <el-table-column prop="type" label="交易类型"> </el-table-column>
        <el-table-column prop="status" label="状态">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status == '正常'" type="success"
              >正常</el-tag
            >
            <el-tag v-else type="info">未审核</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="description" label="描述"> </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="page-div">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="params.page"
        :page-sizes="[5, 10, 15, 20, 30]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { pageQueryEmployeeAccount } from "@/api/account";
import { pageQuery as pageQueryEmployee } from "@/api/user";
import { fmtTableDateDay } from "@/filters/index";
export default {
  data() {
    return {
      // 时间格式
      fmtTableDateDay,
      //   时间数组
      dataValue: [],
      //   表格数据
      tableData: {},
      //   分页参数
      params: {
        page: 1,
        pageSize: 10,
      },
      // 总条数
      total: 0,
      //   搜索输入的数据
      searchForm: {},
      // 员工数据
      employeeData: {},
      //   日期时间选择器数据处理
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  watch: {
    // 深度监听分页参数
    params: {
      handler() {
        this.pageQueryEmployeeAccountData();
      },
      deep: true,
    },
  },
  created() {
    this.pageQueryEmployeeAccountData();
    this.pageQueryemployeeData();
  },
  methods: {
    //   请求员工账单数据
    async pageQueryEmployeeAccountData() {
      let res = await pageQueryEmployeeAccount(this.params);
      this.tableData = res.data.list;
      this.total = res.data.total;
    },
    // 请求员工信息数据
    async pageQueryemployeeData() {
      let res = await pageQueryEmployee({ page: 1, pageSize: 1000, roleId: 1 });
      this.employeeData = res.data.list;
    },
    // 条/页 发生变化时
    handleSizeChange(val) {
      this.params = {
        page: 1,
        pageSize: val,
      };
    },
    // 页数发生变化时
    handleCurrentChange(val) {
      this.params.page = val;
    },
    // 点击查询按钮
    async toSearch() {
      let temp = {
        ...this.params,
        ...this.searchForm,
      };
      if (this.dataValue) {
        if (this.dataValue.length > 0) {
          temp.beginTime = this.dataValue[0];
          temp.endTime = this.dataValue[1];
        }
      }
      for (let key in temp) {
        if (!temp[key]) {
          delete temp[key];
        }
      }
      let res = await pageQueryEmployeeAccount(temp);
      this.tableData = res.data.list;
      this.total = res.data.total;
    },
  },
};
</script>


<style scoped>

</style>